package cn.myzqu.sign.user.server.api;

import cn.myzqu.sign.common.response.ResultData;
import cn.myzqu.sign.message.common.input.MessageInput;
import cn.myzqu.sign.project.client.ProjectClient;
import cn.myzqu.sign.project.common.input.ProjectQueryInput;
import cn.myzqu.sign.user.server.client.MessageClientService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

@RestController
@RequestMapping("/test")
@Api("测试api")
@Slf4j
public class TestApi {

    @Autowired
    private MessageClientService messageClientService;

    @Autowired
    private ProjectClient projectClient;

    @GetMapping("/project")
    @ApiOperation("测试获取项目")
    public ResultData getProject() {
        ProjectQueryInput projectQueryInput = new ProjectQueryInput();
        projectQueryInput.setCreateUserId("11002");
        return projectClient.searchProject(projectQueryInput);
    }

    @GetMapping("/message")
    @ApiOperation("测试调用插入消息")
    public ResultData getMessage(){
        MessageInput messageInput = new MessageInput();
        messageInput.setTheme("user服务插入信息");
        messageInput.setReceiverId(122);
        messageInput.setSenderId(123);
        //messageInput.setContent("user服务插入信息");
        return ResultData.success(messageClientService.addMessage(messageInput));
    }

    @GetMapping("/status")
    @ApiOperation("测试修改消息状态")
    public ResultData get(){
        ResultData resultData = messageClientService.changeReadStatus(32);
        log.info("code:{},msg:{},data:{}",resultData.getCode(),resultData.getMsg(),resultData.getData());
        return ResultData.success();
    }

    @GetMapping("/user/{userId}")
    @ApiOperation("测试获取用户消息")
    public ResultData getMessageByUserId(@PathVariable Integer userId){
        ResultData resultData = messageClientService.getMessageByUserId(userId,1,10);
        log.info("resultData:{}",resultData.toString());
        return resultData;
    }


}
